<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Support\Facades\Log;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //监听sql
        DB::listen(function(QueryExecuted $query)
        {
            $data = ['sql'=>$query->sql,'param'=>$query->bindings,'time'=>$query->time];
            Log::channel('sql')->debug('',$data);
        });
    }
}
